const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';
const jsonflatten = require('pt-core-common').util.jsonflatten;

const getAdditionalSellerInputs = {};
getAdditionalSellerInputs.generateOption = function(seller_id, mws_auth_token, orderId, shippingServiceId, shipFromAddress){
  let baseOption = {
    'Version': '2015-06-01',
    'Action': 'CreateShipment',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'OrderId': orderId,
    'ShippingServiceId': shippingServiceId,
    // 'ShipFromAddress': '',
  };

  const option = Object.assign(baseOption, jsonflatten.flatten(shipFromAddress, null, baseIndex=1));
  return option;
};

getAdditionalSellerInputs._ = function(options) {
  if (!isProduction) {
    return amazonMws.merchantFulfillment.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

getAdditionalSellerInputs.getAdditionalSellerInputs = function(seller_id, mws_auth_token, orderId, shippingServiceId, shipFromAddress) {
  return this._(this.generateOption(seller_id, mws_auth_token, orderId, shippingServiceId, shipFromAddress));
};

module.exports = getAdditionalSellerInputs;